home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / prset / prsetup.frm < prev    next >
Text File  |  1995-05-08  |  9KB  |  310 lines

  1. VERSION 2.00
  2. Begin Form PrintSetup 
  3.    BackColor       =   &H00FFFF00&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Printer Setup"
  6.    ClientHeight    =   4200
  7.    ClientLeft      =   3465
  8.    ClientTop       =   2430
  9.    ClientWidth     =   6495
  10.    Height          =   4605
  11.    Left            =   3405
  12.    LinkMode        =   1  'Source
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   4200
  17.    ScaleWidth      =   6495
  18.    Top             =   2085
  19.    Width           =   6615
  20.    Begin CommandButton Command3 
  21.       Caption         =   "Setup ..."
  22.       FontBold        =   -1  'True
  23.       FontItalic      =   0   'False
  24.       FontName        =   "MS Sans Serif"
  25.       FontSize        =   9.75
  26.       FontStrikethru  =   0   'False
  27.       FontUnderline   =   0   'False
  28.       Height          =   495
  29.       Left            =   4800
  30.       TabIndex        =   3
  31.       Top             =   3120
  32.       Width           =   1575
  33.    End
  34.    Begin CommandButton Command2 
  35.       Caption         =   "Cancel"
  36.       FontBold        =   -1  'True
  37.       FontItalic      =   0   'False
  38.       FontName        =   "MS Sans Serif"
  39.       FontSize        =   9.75
  40.       FontStrikethru  =   0   'False
  41.       FontUnderline   =   0   'False
  42.       Height          =   495
  43.       Left            =   4800
  44.       TabIndex        =   2
  45.       Top             =   1440
  46.       Width           =   1575
  47.    End
  48.    Begin CommandButton Command1 
  49.       Caption         =   "OK"
  50.       Default         =   -1  'True
  51.       FontBold        =   -1  'True
  52.       FontItalic      =   0   'False
  53.       FontName        =   "MS Sans Serif"
  54.       FontSize        =   9.75
  55.       FontStrikethru  =   0   'False
  56.       FontUnderline   =   0   'False
  57.       Height          =   495
  58.       Left            =   4800
  59.       TabIndex        =   1
  60.       Top             =   480
  61.       Width           =   1575
  62.    End
  63.    Begin ListBox List1 
  64.       FontBold        =   -1  'True
  65.       FontItalic      =   0   'False
  66.       FontName        =   "MS Sans Serif"
  67.       FontSize        =   9.75
  68.       FontStrikethru  =   0   'False
  69.       FontUnderline   =   0   'False
  70.       Height          =   3150
  71.       Left            =   120
  72.       TabIndex        =   0
  73.       Top             =   480
  74.       Width           =   4455
  75.    End
  76.    Begin Label Label2 
  77.       BackColor       =   &H00FFFF00&
  78.       Caption         =   "Copyright (c) 1991 Corey Schwartz, Programmer's Warehouse 602-443-0580, 73240,2734 All Rights Reserved"
  79.       Height          =   375
  80.       Left            =   120
  81.       TabIndex        =   5
  82.       Top             =   3720
  83.       Width           =   6375
  84.    End
  85.    Begin Label Label1 
  86.       BackColor       =   &H00FFFF00&
  87.       Caption         =   "&Printer"
  88.       FontBold        =   -1  'True
  89.       FontItalic      =   0   'False
  90.       FontName        =   "MS Sans Serif"
  91.       FontSize        =   9.75
  92.       FontStrikethru  =   0   'False
  93.       FontUnderline   =   0   'False
  94.       Height          =   255
  95.       Left            =   120
  96.       TabIndex        =   4
  97.       Top             =   120
  98.       Width           =   1695
  99.    End
  100. End
  101.  
  102. Const DM_UPDATE = 1
  103. Const DM_COPY = 2
  104. Const DM_PROMPT = 4
  105. Const DM_MODIFY = 8
  106. Const SIZETEMPBUFF = 80
  107. Const MAXKEYBUFFER = 300
  108.  
  109. Declare Function CallProc Lib "CallAddr.DLL" (ByVal fnc&, ByVal hWnd%, ByVal hDrv%, ByVal dmOut&, ByVal lpName$, ByVal lpPort$, ByVal dmIn&, ByVal lpPro As Any, ByVal wMode%) As Integer
  110. Declare Function GetProcAddress Lib "Kernel" (ByVal hDrv%, ByVal Esc As String) As Long
  111.  
  112.  
  113. Sub AccessPrinter (UpdatePrt As Integer)
  114.     Dim lpName As String
  115.     Dim lpPort As String
  116.     Dim lpDriver As String
  117.     Dim TempStr As String
  118.     Dim hMem As Integer
  119.     Dim lpfnMode As Long
  120.     Dim hDriver As Integer
  121.     Dim Flags As Integer
  122.  
  123.     If List1.ListIndex = -1 Then
  124.     Exit Sub
  125.     End If
  126.  
  127.     Screen.MousePointer = 11
  128.     TempStr = List1.list(List1.ListIndex)
  129.     x = lbParse(TempStr, lpName, lpPort, lpDriver)
  130.     hDriver = LoadLibrary(lpDriver)
  131.     If (hDriver >= 32) Then
  132.     lpfnMode = GetProcAddress(hDriver, "EXTDEVICEMODE")
  133.     If (lpfnMode <> 0) Then
  134.        wSizeDM = CallProc(lpfnMode, 0&, hDriver, 0&, lpName, lpPort, 0&, 0&, 0)
  135.        If (wSizeDM <> 0) Then
  136.            hMem = GlobalAlloc(GHND, wSizeDM)
  137.            If (hMem <> 0) Then
  138.             pDM = GlobalLock(hMem)
  139.             dummy = CallProc(lpfnMode, 0&, hDriver, pDM, lpName, lpPort, 0&, "WIN.INI", DM_COPY)
  140.             wFlags = DM_UPDATE Or DM_MODIFY
  141.             If UpdatePrt Then
  142.                wFlags = wFlags Or DM_PROMPT
  143.             End If
  144.             dummy = CallProc(lpfnMode, 0&, hDriver, 0&, lpName, lpPort, pDM, "WIN.INI", wFlags)
  145.             dummy = GlobalUnlock(hMem)
  146.            End If
  147.        End If
  148.     End If
  149.     FreeLibrary (hDriver)
  150.     End If
  151.     Screen.MousePointer = 0
  152.  
  153. End Sub
  154.  
  155. Sub Command1_Click ()
  156.     If List1.ListIndex >= 0 Then
  157.     AccessPrinter (False)
  158.     End If
  159.     Unload PrintSetup
  160. End Sub
  161.  
  162. Sub Command1_KeyPress (KeyAscii As Integer)
  163.     kbDaemon (KeyAscii)
  164. End Sub
  165.  
  166. Sub Command2_Click ()
  167.     Unload PrintSetup
  168. End Sub
  169.  
  170. Sub Command2_KeyPress (KeyAscii As Integer)
  171.     kbDaemon (KeyAscii)
  172. End Sub
  173.  
  174. Sub Command3_Click ()
  175.     AccessPrinter (True)
  176. End Sub
  177.  
  178. Sub Command3_KeyPress (KeyAscii As Integer)
  179.     kbDaemon (KeyAscii)
  180. End Sub
  181.  
  182. Sub Form_KeyPress (KeyAscii As Integer)
  183.     kbDaemon (KeyAscii)
  184. End Sub
  185.  
  186. Sub Form_Load ()
  187.     lbsetup List1
  188. End Sub
  189.  
  190. Sub kbDaemon (KeyAscii As Integer)
  191.     If KeyAscii = Asc("P") Or KeyAscii = Asc("p") Then
  192.     List1.GotFocus = True
  193.     End If
  194. End Sub
  195.  
  196. Function lbLookup (c As Control, Key As String)
  197.     x% = c.ListCount - 1
  198.     For i% = 0 To x%
  199.     If (c.list(i%) = Key) Then
  200.         lbLookup = i%
  201.         Exit Function
  202.     End If
  203.     Next
  204.     lbLookup = -1
  205. End Function
  206.  
  207. Function lbParse (SrcString As String, lpPrinter As String, lpPort As String, lpDriver As String) As Integer
  208.     'We assume that the input string is
  209.     'in the form: <Printer> on <Port>
  210.  
  211.     Dim cBuff1 As String * SIZETEMPBUFF
  212.     Dim fstru As OFSTRUCT
  213.  
  214.     i = Len(SrcString)
  215.     strlen = i
  216.     While (i > 0 And Mid$(SrcString, i, 1) <> " ")
  217.     i = i - 1
  218.     Wend
  219.  
  220.     lpPort = Trim(Mid$(SrcString, i + 1, strlen - i))
  221.     lpPrinter = Trim$(Mid$(SrcString, 1, i - 3))
  222.  
  223.     x = GetProfileString("devices", ByVal lpPrinter, ByVal 0&, cBuff1, SIZETEMPBUFF)
  224.     lpDriver = Trim(Mid$(cBuff1, 1, InStr(cBuff1, ",") - 1))
  225.  
  226.     x = InStr(lpDriver, ".")
  227.     If x = 0 Then
  228.     lpDriver = lpDriver + ".Drv"
  229.     End If
  230.  
  231.     x = OpenFile(lpDriver, fstru, OF_EXIST Or OF_READ)
  232.     If (x = -1) Then
  233.     lbParse = -1
  234.     Exit Function
  235.     End If
  236.  
  237.     lbParse = 1
  238.     
  239.     
  240. End Function
  241.  
  242.  
  243. Sub lbsetup (lb As Control)
  244.  
  245. Dim cBuff1 As String * SIZETEMPBUFF
  246. Dim lpKeyList As String * MAXKEYBUFFER
  247. Dim Str1 As String
  248. Dim i As Integer
  249. Dim j As Integer
  250. Dim lpKeyName As String
  251. Dim DeviceName As String
  252.  
  253.  
  254.     StrIndex = 1
  255.     j = GetProfileString("Devices", ByVal 0&, "No Devices Available", lpKeyList, MAXKEYBUFFER)
  256.     While (StrIndex <= j)
  257.     NullPos = InStr(StrIndex, lpKeyList, Chr$(0))
  258.     lpKeyName = Mid$(lpKeyList, StrIndex, NullPos - StrIndex)
  259.     cBuff1 = String$(SIZETEMPBUFF, Chr$(0))
  260.     i = GetProfileString("Devices", ByVal lpKeyName, ByVal 0&, cBuff1, SIZETEMPBUFF)
  261.     
  262.     'The string Returned should be in the form:
  263.     '   PCL / HP LaserJet,HPPCL,LPT1:,LPT2:
  264.  
  265.     'Get the device Name
  266.     x = InStr(1, cBuff1, ",") + 1
  267.     'Loop Through the devices adding a string to the listbox Control
  268.     Done = 0
  269.     While (Not Done)
  270.         NextComma = InStr(x, cBuff1, ",")
  271.         If NextComma = 0 Then
  272.         NextComma = i + 1
  273.         Done = -1
  274.         End If
  275.  
  276.         Str1 = lpKeyName + " on " + Mid$(cBuff1, x, NextComma - x)
  277.         lb.AddItem Str1
  278.         x = NextComma + 1
  279.     Wend
  280.     StrIndex = NullPos + 1
  281.     Wend
  282.     
  283.     '-------------------
  284.     'Get Default Printer
  285.     cBuff1 = String$(SIZETEMPBUFF, Chr$(0))
  286.     i = GetProfileString("Windows", "Device", ByVal 0&, cBuff1, SIZETEMPBUFF)
  287.     
  288.     x = InStr(1, cBuff1, ",") + 1
  289.     NextComma = InStr(x, cBuff1, ",")
  290.     If NextComma = 0 Then
  291.